package com.cet.qz.unit01.chapter1_2;

import edu.princeton.cs.algs4.*;

import javax.xml.parsers.ParserConfigurationException;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-01-24 22:08
 **/
public class Interval2D_Test {

    public static void main(String[] args) throws ParserConfigurationException {
        System.out.println("请输入与坐标轴平行的矩形的区间：");
        System.out.println("请输入x轴坐标值域：");
        double xlo = StdIn.readDouble();
        double xhi = StdIn.readDouble();
        System.out.println("请输入y轴坐标值域：");
        double ylo = StdIn.readDouble();
        double yhi = StdIn.readDouble();

        /*
        *     这里我们都在默认画布范围内操作，所有不需要预先设定画布的范围
        *     private static final double DEFAULT_XMIN = 0.0;
        *     private static final double DEFAULT_XMAX = 1.0;
        *     private static final double DEFAULT_YMIN = 0.0;
        *     private static final double DEFAULT_YMAX = 1.0;
        *
        *
        * */
        Interval1D xinterval = new Interval1D(xlo, xhi);
        Interval1D yinterval = new Interval1D(ylo, yhi);
        Interval2D box = new Interval2D(xinterval, yinterval);
        box.draw();

        Counter c = new Counter("hits");

        for (int i = 0; i < 10000; i++) {
            double x = Math.random();
            double y = Math.random();
            Point2D p = new Point2D(x, y);
            if (box.contains(p)) {
                c.increment();
            } else {
                p.draw();
            }
        }
        System.out.println(c);
        System.out.println(box.area());
    }
}
